package com.kuanter.kuanterauto.adapter;

import java.util.ArrayList;
import java.util.List;

import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.kuanter.kuanterauto.R;
import com.kuanter.kuanterauto.constants.MainConstants;
import com.kuanter.kuanterauto.entity.KuanterService;

public class PopServiceTypeAdapter extends BaseAdapter {
	LayoutInflater factory;
	public static int selected = 0;
	private List<KuanterService> serviceData = new ArrayList<KuanterService>();
	
	public PopServiceTypeAdapter(LayoutInflater factory) {
		this.factory = factory;
	}

	@Override
	public int getCount() {
		int size = 0;
		if(serviceData != null) {
			size = serviceData.size();
		}
		return size;
	}

	@Override
	public Object getItem(int position) {
		return serviceData.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View conview, ViewGroup parent) {
		if(conview == null) {
			conview = factory.inflate(R.layout.list_servicetype_item, null);
		}
		TextView service_type = (TextView) conview.findViewById(R.id.service_type);
//		LayoutParams lp = new LayoutParams(LayoutParams.FILL_PARENT, 50);
//		service_type.setLayoutParams(lp);
//		service_type.setGravity(Gravity.CENTER);
		service_type.setText(serviceData.get(position).getServiceType());
		if(position == selected) {
			conview.setBackgroundResource(R.color.pop_condicition_type_selected);
			service_type.setTextColor(Color.WHITE);
		} else {
			conview.setBackgroundResource(R.drawable.list_site_selector);
//			conview.setBackgroundDrawable(null);
			service_type.setTextColor(Color.parseColor("#787878"));
		}
		return conview;
	}

	public List<KuanterService> getServiceData() {
		return serviceData;
	}

	public void setServiceData(List<KuanterService> serviceData) {
//		this.serviceData = serviceData;
		this.serviceData.addAll(serviceData);
		List<KuanterService> delete = new ArrayList<KuanterService>();
		for(int i = 0; i < this.serviceData.size(); i++) {
			KuanterService ks = this.serviceData.get(i);
			if(ks.getServiceID().equals(MainConstants.CW)) {
//				this.serviceData.remove(ks);
				delete.add(ks);
			} else if(ks.getServiceID().equals(MainConstants.DJ)) {
//				this.serviceData.remove(ks);
				delete.add(ks);
			} else if(ks.getServiceID().equals(MainConstants.QT)) {
//				this.serviceData.remove(ks);
				delete.add(ks);
			}
		}
		this.serviceData.removeAll(delete);
	}

}
